local kuanggu = fk.CreateSkill{
  name = "iberia_kuanggu",
}

Fk:loadTranslationTable{
  ["iberia_kuanggu"] = "狂骨",
  [":iberia_kuanggu"] = "每回合限一次，你可以将一张【闪】当【决斗】使用。若你因此造成伤害，你摸两张牌。",
}

kuanggu:addEffect("viewas", {
  anim_type = "offensive",
  max_turn_use_time = 1,
  pattern = "duel",
  card_filter = function (self, player, to_select, selected)
    if #selected > 0 then return end
    return Fk:getCardById(to_select).trueName == "jink"
  end,
  view_as = function (self, player, cards)
    if #cards ~= 1 then return end
    local duel = Fk:cloneCard("iberia__duel")
    duel.skillName = kuanggu.name
    duel:addSubcards(cards)
    return duel
  end,
  enabled_at_play = function (self, player)
    return player:usedSkillTimes(kuanggu.name) < 1
  end,
  enabled_at_response = function (self, player, response)
    return player:usedSkillTimes(kuanggu.name) < 1 and not response
  end
})

kuanggu:addEffect(fk.CardUseFinished, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    if player == target and table.contains(data.card.skillNames, kuanggu.name) then
      local room = player.room
      local filter = function (e)
        return e.data.card == data.card and e.data.from == player
      end
      return #room.logic:getActualDamageEvents(1, filter) == 1
    end
  end,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function (self, event, target, player, data)
    player.room:drawCards(player, 2, kuanggu.name)
  end
})

return kuanggu